﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using PoolGame2.Networking;
using PoolGame2.Player;
using PoolGame2.Managers;

namespace PoolGame2.Menus
{
    public class PlayerPresencePanel : Overlay
    {
        public PlayerPresencePanel(PoolGame game)
            : base(game)
        {
            BGAlpha = 0.0f;
            size = new Vector2(game.GraphicsDevice.Viewport.Width - 20, 50);
            position = new Vector2( 10, game.GraphicsDevice.Viewport.Height - 105 );
        }

        public override void Draw(GameTime gameTime)
        {
            if(((PoolGame)base.Game).gameManager != null){
                if (((PoolGame)base.Game).gameManager.GetState() != ManagerGame.GameState.GAME_PAUSED)
                {
                    base.Draw(gameTime);

                    PoolGame pGame = (PoolGame)Game;
                    float offset = 0.0f;
                    foreach (PlayerPresence player in pGame.signedInPlayers)
                    {
                        Gamer gamer = player.GetLiveGamer();
                        if (gamer != null)
                        {
                            GamerProfile profile = gamer.GetProfile();
                            PoolGame poolGame = (PoolGame)Game;
                            SpriteBatch spriteBatch = poolGame.spriteBatch;
                            Rectangle fullscreen = new Rectangle((int)(position.X + offset), (int)position.Y, (int)50, (int)50);

                            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
                            spriteBatch.Draw(profile.GamerPicture, fullscreen, Color.White);
                            spriteBatch.DrawString(poolGame.fontDatabase.loadFont("Arial"), gamer.Gamertag, new Vector2(position.X + 70.0f + offset, position.Y + 22), Color.White);
                            spriteBatch.End();

                            offset += 100;
                        }
                    }
                }
            }
        }
    }
}
